<form action="index.php/contract/update/" method="post" enctype="multipart/form-data" name="myform" id="myform">
<div id="inline1">
<h2><span>合同信息</span></h2>
<table>
        <tr><th colspan="5">基本信息：</th></tr>
        <tr>
        	<td class="name" width="80"><span>*</span>主题：</td>
            <td colspan="4"><input class="text_width" style=" width:427px;" name="subject" id="subject" type="text" value=<?= $update_contract->subject ?> ></input></td>
        </tr>

        <tr>
            <td class="name" width="80"><span>*</span>对应客户：</td>
            <td colspan="4"><input type="text" style=" width:427px;" autocomplete="off" id="customer_name" name="customer_name"  value=<?= $update_contract->customer_name ?> ></input></td>
        </tr>

        <tr>
        	<td class="name" width="80"><span>*</span>对应机会：</td>
            <td colspan="4">
            	<select style="width:427px;" id="opportunity_subject" name="opportunity_id">
                	<option value="<?= $update_contract->opportunity_id ?>"><?= $update_contract->opportunity_subject ?></option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="80">合同号：</td>
            <td width="170"><input type="text"  name="contract_no" value=<?= $update_contract->contract_no ?> ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">总金额：</td>
            <td width="170"><input class="input_bg" name="total_amount" type="text" value=<?= $update_contract->total_amount ?> ></input></td>
        </tr>
        <tr>
        	<td class="name" width="80">付款方式：</td>
            <td width="170">
            	<select name="payment_type">
                	<option value="支票" <?php if($update_contract->payment_type == '支票'):?>selected="selected"<?php endif;?>>支票</option>
                    <option value="现金" <?php if($update_contract->payment_type == '现金'):?>selected="selected"<?php endif;?>>现金</option>
                    <option value="银行转帐" <?php if($update_contract->payment_type == '银行转帐'):?>selected="selected"<?php endif;?>>银行转帐</option>
                    <option value="其它" <?php if($update_contract->payment_type == '其它'):?>selected="selected"<?php endif;?>>其它</option>
                </select>
            </td>
            <td>&nbsp;</td>
            <td class="name" width="80">交付地点：</td>
            <td width="170"><input class="text_width" name="payment_address" type="text" value=<?= $update_contract->payment_address ?> ></input></td>
        </tr>
        <tr>
        	<td class="name" width="80">开始时间：</td>
        	<?php 
		        $starttime= '';
		        if($update_contract->start_time != '0000-00-00 00:00:00'){
		        	$datatime = strtotime($update_contract->start_time);
		        	$starttime = date( "Y-m-d",$datatime);
		        }
        	?>
            <td width="170"><input type="text"  style="background:url(images/calendar.gif) right 1px no-repeat;" name="start_time" class="datepicker" value=<?= $starttime ?> ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">结束时间：</td>
            <?php 
		        $end_time= '';
		        if($update_contract->end_time != '0000-00-00 00:00:00'){
		        	$datatime = strtotime($update_contract->end_time);
		        	$end_time = date( "Y-m-d",$datatime);
		        }
        	?>
            <td width="170"><input type="text"  style="background:url(images/calendar.gif) right 1px no-repeat;" class="datepicker" name="end_time" value=<?= $end_time?> ></input></td>
        </tr>
        <tr>
            <td class="name" width="80">产品：</td>
            <td colspan="4"><input type="text" style=" width:427px;"  name="product" value=<?= $update_contract->product ?> ></input></td>
        </tr>
        <tr>
        	<td class="name" width="80">客户签约人：</td>
            <td width="170"><input type="text" name="customer_contract" value=<?= $update_contract->customer_contract ?> ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">我方签约人：</td>
            <td width="170"><input type="text" name="our_contract"  value=<?= $update_contract->our_contract ?> ></input></td>
        </tr>
        <?php 
                    		$user_name = $this->session->userdata('username');
                       		$role = $this->session->userdata('role');
                       		?>
        <tr>
        	<td class="name" width="80">所有者：</td>
        	<td width="170">
        	<?php if($role != '商务助理'):?>
        		<input type="text" name="user_name" value=<?= $update_contract->user_name ?> ></input>
        	<?php endif;?>
        	<?php if($role == '商务助理'):?>
            	<select name="user_name">
                    	<?php foreach ($all_users as $item_user):?>
                    		<?php if($item_user->user_name != '何俊斌'):?>
                    			<option value="<?= $item_user->user_name?>" <?php if($item_user->user_name == $update_contract->user_name):?> selected='selected' <?php endif;?>><?= $item_user->user_name?></option>
                    		<?php endif;?>
                        <?php endforeach;?>
            <?php endif;?>
            </td>
            <td>&nbsp;</td>
            <td class="name" width="80">签约时间：</td>
            <?php 
		        $signing_time= '';
		        if($update_contract->signing_time != '0000-00-00 00:00:00'){
		        	$datatime = strtotime($update_contract->signing_time);
		        	$signing_time = date( "Y-m-d",$datatime);
		        }
        	?>
            <td width="170"><input type="text"  style="background:url(images/calendar.gif) right 2px no-repeat;" class="datepicker" name="signing_time"  value=<?= $signing_time?> ></input></td>
        </tr>
        <tr><th colspan="5">执行状态：</th></tr>
        <tr>
            <!--<td class="name" width="80">回款金额：</td>
            <td width="170"><input type="text" name="payment_amount" value=<?= $update_contract->payment_amount ?> ></input></td>
            <td>&nbsp;</td>-->
            <td class="name" width="80">状态：</td>
            <td width="170" colspan="4">
            	<select name="status">
                    <option <?php if($update_contract->status == '执行中'):?>selected="selected"<?php endif;?>>执行中</option>
                    <option <?php if($update_contract->status == '完成'):?>selected="selected"<?php endif;?>>完成</option>
                    <option <?php if($update_contract->status == '意外中止'):?>selected="selected"<?php endif;?>>意外中止</option>
                </select>
            </td>
        </tr>
        <tr><th colspan="5">其他：</th></tr>
        <tr>
            <td class="gj_name" width="80">合同正文及<br />附件：</td>
            <td colspan="4">
            	<!--<input type="file" name="userfile" size="20" />-->
                <div class="tract_con">
                    <input type="text" class="tract_text" name="textfield" id="textfield" value="" />
                    <input type='button' class="tract_but" value='浏览' />
                    <input type="file" class="tract_file" name="userfile" onchange="document.getElementById('textfield').value=this.value" />
                </div>
            </td>
        </tr>
		<tr>
            <td class="gj_name" width="80">备注：</td>
            <td colspan="4"><textarea name="remark" value= ><?= $update_contract->remark ?></textarea></td>
        </tr>
        <?php if($payment_records):?>
	    <tr><th colspan="5">回款记录：</th></tr>
	    <?php endif;?>
	    <?php foreach($payment_records as $payment_record):?>
	    <?php 
	    $datatime = strtotime($payment_record->payment_time);
	    $payment_time = date( "Y-m-d",$datatime);
	    ?>
	        <tr>
	            <td colspan="7"><span class="span_right">期次：<?= $payment_record->stages?></span><span class="span_right">金额：<?= $payment_record->money?></span><span class="span_right">日期：<?php echo $payment_time;?></span></td>
	        </tr>
	 	<?php endforeach;?>
        <tr><td colspan="5">&nbsp;</td></tr>
        <tr class="sub">
            <td colspan="5"><input type="button" id="edit_tijiao" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重置" /></td>
        </tr>
    </table>
</div>
<input type="hidden" name="contract_id" value=<?= $update_contract->contract_id?> >
<input type="hidden" name="customer_id" value=<?= $update_contract->customer_id?> >
<input type="hidden" name="hicuname" value=<?= $update_contract->customer_name?> >
<input type="hidden" name="hiusname" value=<?= $update_contract->user_name?> >
<input type="hidden" name="hitext" value=<?= $update_contract->text_attachments?> >
<input type="hidden" name="hireal" value=<?= $update_contract->real_file_name?> >
<input type="hidden" id="type" value="1" ></input>
</form>
<script type="text/javascript">
$(function() {
		$( ".datepicker" ).datepicker();

		$("#edit_tijiao").click(function(){
			var error="";
			var subject = $("#subject").val();
			var customer_name = $("#customer_name").val();
			var opportunity_subject = $("#opportunity_subject").val();

			if(subject == ''){
				error+="主题不允许为空,请填写\x0d";
				if(customer_name == ''){
					$("#subject").focus();
				}
			}
			if(customer_name == ''){
				error+="对应客户不允许为空,请填写\x0d";
				if(subject != ''){
					$("#customer_name").focus();
				}
			}
			if(opportunity_subject == null){
				 error+="对应机会不允许为空,请填写\x0d";
				 if(customer_name == '' && subject != ''){
					 $("#customer_name").focus();
					 }
				 if(customer_name != '' && subject == ''){
					 $("#subject").focus();
					 }
			}
			if(error != ""){
		    	alert(error);
		    }else{
			    $("#myform").submit();
		    }
			})
});
</script>
